<!-- D:\project\app\ydz-app-uniapp\static\images\forum -->
<template>
	<view class="pagebody">
		<view class="topbox">
			<view class=" align-center">
				<view class=" flex-row align-center">
					<image @click="backpage" src="@/static/images/login/leftjt.png" alt=""
						style="width: 48rpx;height: 48rpx;"></image>
				</view>
				<view class="color303b39 fz40 fwbold" style="margin-left: 263rpx;">
					我的帖子
				</view>
			</view>
		</view>

		<view class="postbox">
			<view class="postcard mt16" style="border-radius: 32rpx;" v-for="(item,index) in postlist" :key="index">
				<view class="">
					<view class="cardtop flex-row justify-between">
						<view class="flex-row">
							<image style="width: 68rpx;height: 68rpx;border-radius: 50%;flex-shrink: 0;" :src="baseUrl+item.invAvatar" mode="">
							</image>
							<view class="ml16">
								<view class="flex-row">
									<view class="color303b39 fz32">
										{{item.invName}}
									</view>
								</view>
								<view class="mt16" style="color: #7E8987; font-size: 24rpx;">
									{{item.createTime?item.createTime.slice(0,10):item.updateTime.slice(0,10)}}
								</view>
							</view>
						</view>
						<view class="flex-row" @click="openlh(item)">
							<view class="" style="height:6rpx;width: 6rpx;background: #B8C3C1;border-radius: 50%;">
							</view>
							<view class=""
								style="margin: 0 6rpx;height:6rpx;width: 6rpx;background: #B8C3C1;border-radius: 50%;">
							</view>
							<view class="" style="height:6rpx;width: 6rpx;background: #B8C3C1;border-radius: 50%;">
							</view>
						</view>
					</view>
					<view @click="todetail(item)" class="cardtitle color303b39 fwbold"
						style="font-size: 32rpx;margin-top: ;">
						{{item.title}}
					</view>
					<view @click="todetail(item)" class="cardcontent color303b39 mt25 lineclamp4">
						{{item.content}}
					</view>
				</view>
				<!-- 				<view @click="todetail(item)" class="cardimgs flex-row ofx mt25">
					<image v-for="(item,index) in item.attachFiles" :key="index" class="mr16" style="flex-shrink: 0;width: 320rpx;height: 320rpx;border-radius: 16rpx;"
						:src="item.url" mode=""></image>
				</view> -->
				<view @click="todetail(item)" v-if="item.attachFiles!=null&&item.attachFiles.length>0" class="cardimgs flex-row ofx mt25 "
					style="">
					<view v-for="(element,index1) in item.attachFiles" :key="index1" class="imgbox "
						:style="{ background: 'url(' + element.url + ') no-repeat' }">
					</view>
				</view>

				<view class="cardbot justify-around align-center mt25"
					style="height: 96rpx;border-top: 1rpx solid #F4F8F8;">
<!-- 					<view class="flex-row align-center">
						<image src="../../static/images/forum/share.png"
							style="width: 40rpx;height: 40rpx;margin-right: 16rpx;" mode=""></image>
						分享
					</view> -->
					<view class="flex-row align-center">
						<image @click="clicknice(item)"
							:src="item.isLike?'../../static/images/forum/isnice.png':'../../static/images/forum/nice.png'"
							style="width: 40rpx;height: 40rpx;margin-right: 16rpx;" mode=""></image>
						{{item.likeCount?item.likeCount:0}}
					</view>
					<view class="flex-row align-center">
						<image @click="clicklike(item)"
							:src="item.isCollect?'../../static/images/forum/islike.png':'../../static/images/forum/like.png'"
							style="width: 40rpx;height: 40rpx;margin-right: 16rpx;" mode=""></image>
						{{item.collectCount?item.collectCount:0}}
					</view>
				</view>
			</view>
		</view>
		<view class="addbtn align-center justify-center" @click="addpost" style="">
			+
		</view>
		<!-- 弹出层 === 举报拉黑 -->
		<u-popup v-model="lhshow" mode="bottom">
			<view class="bgfff" style="padding: 64rpx 41rpx 24rpx;">
				<view class="justify-around align-center">
					<view v-show="!isOwner" @click="tojbpage" class="justify-center align-center flex-col">
						<image src="../../static/images/forum/jubao.png"
							style="width: 56rpx;height: 56rpx;margin-bottom: 16rpx;" mode=""></image>
						<view class="color303b39 ">
							举报
						</view>
					</view>
					<view v-show="isOwner" class="justify-center align-center flex-col" @click="delshow = true">
						<image src="../../static/images/forum/delete.png"
							style="width: 56rpx;height: 56rpx;margin-bottom: 16rpx;" mode=""></image>
						<view class="color303b39 ">
							删除
						</view>
					</view>
				</view>
				<view class="mt40 align-center justify-center" style="height: 100rpx;">
					<span @click="lhshow = false">取消</span>
				</view>
			</view>
		</u-popup>
		<u-modal v-model="delshow" :show-cancel-button="true" :confirm-text="'删除'" @confirm="delpost"
			@cancel="nodelpost" :cancel-text="'取消'" content="是否删除该帖子？"></u-modal>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import {
		getOwnerinvlist,
		invlike,
		getDicts,
		invcollectAdd,
		delInvitation
	} from '@/api/api.js'
	import config from '@/config'
	import FixedFoot from '../../layouts/fixedfoot.vue';
	export default {
		components: {
			FixedFoot,
		},
		onLoad() {

		},
		data() {
			return {
				baseUrl:config.baseUrl,
				navlist: [],
				isnavindex: 0,
				navvalue: 0,
				lmlist: [],
				islmindex: 0,
				lmvalue: 0,
				topPostlist: [],
				postlist: [],
				lhshow: false,
				lhdelid: null,
				delshow: false,
				isOwner:false,
			}
		},
		created() {
			this.getpostlist()
		},
		mounted() {
			uni.$on('update', function(data) {
					//触发更新后
					console.log('update回来了',data)
				})
		},
		onBackPress(options) {
			this.refreshData();
		},

		methods: {
			addpost() {
				uni.navigateTo({
					url: '/pages/forum/addpost'
				})
			},
			backpage(){
				uni.navigateBack({
					delta: 1
				});
			},
			tojbpage() {
				uni.navigateTo({
					url: "/pages/forum/reportpage?type=0&tzid=" + this.lhdelid
				})
			},
			getpostlist() {
				getOwnerinvlist().then(response => {
					this.postlist = response.rows
				})
			},
			todetail(item) {
				uni.navigateTo({
					url: '/pages/forum/forumdetail?id=' + item.id
				})
			},
			clicknice(item) {
				let status = 0
				item.isLike = !item.isLike
				if (item.isLike == true) {
					status = 0
					item.likeCount++
				} else {
					status = 1
					item.likeCount--
				}
				let data = {
					invitationId: item.id,
					status: status
				}
				invlike(data).then(res => {})
			},
			clicklike(item) {
				let status = 0
				item.isCollect = !item.isCollect
				if (item.isCollect == true) {
					status = 0
					item.collectCount++
				} else {
					status = 1
					item.collectCount--
				}
				let data = {
					invitationId: item.id,
					status: status
				}
				invcollectAdd(data).then(res => {})
			},
			// 拉黑删除弹窗
			openlh(item) {
				this.lhshow = true
				this.lhdelid = item.id
				this.isOwner = true
			},

			// 删除操作
			delpost() {
				delInvitation(this.lhdelid).then(res => {
					this.$refs.uToast.show({
						title: '帖子已删除',
						type: 'success',
					})
					this.lhshow = false
					this.getpostlist()
				})
			},

			// 不删除
			nodelpost() {
				this.delshow = false;
			}
		},

	}
</script>

<style lang="scss" scoped>
	.pagebody {
		padding-bottom: 136rpx;
		background: #F0F6F5;
		.topbox {
			height: 88rpx;
			background: #fff;
			padding: 20rpx 24rpx;
		}

		.postbox {
			.postcard {
				background: #fff;
				padding: 48rpx 24rpx 0rpx;

				.cardtop {}

				.cardtitle {
					margin-top: 24rpx;
				}

				.imgbox {
					height: 320rpx;
					width: 320rpx;
					flex-shrink: 0;
					background-size: cover !important;
					border-radius: 16rpx;
					background-position: center !important;
					margin: 0 15rpx 15rpx 0;
				}

			}
		}

		.addbtn {
			position: fixed;
			bottom: 120rpx;
			right: 26rpx;
			width: 88rpx;
			height: 88rpx;
			border-radius: 50%;
			background: linear-gradient(140deg, #4EF2C9 0%, #00D9B2 100%);
			box-shadow: 0px 0px 16px 0px rgba(0, 151, 124, 0.3);
			font-size: 88rpx;
			text-align: center;
			// line-height: 88rpx;
			color: #fff;
		}
	}
</style>